home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 013 / sred.arc / SRED.ASM next >
Encoding:
Assembly Source File  |  1985-12-27  |  17.5 KB  |  315 lines

  1. RED segment para public 'code'
  2.         assume  cs:RED, ds:RED, es:RED, ss:NOTHING
  3.         org     100h            ; .COM format
  4. BEGIN:
  5.         jmp     CODE_START      ; Jump around data declarations
  6. ;
  7. ;        The original program (still very much the same) appeared in
  8. ;     PC Magazine. I added the selection feature to it.
  9. ;        To have the program perform as originally intended simply remove
  10. ;     the call to 'promptYN'.
  11. ;
  12. DECLARE:        ; Messages, Storage Areas, Equates
  13. COPYRIGHT       db      'SREDirect (C) 1985, Dickinson Associates Inc.'
  14.                 db      13,10
  15.                 db      '       modified by  John Toledo   12/26/85'
  16.                 db      13,10,13,10,'$'
  17. PATH_FILE_LEN   equ     77  ;Length = 1, Path = 63, FileName = 12, 0 = 1
  18. SOURCE_FILE     db      PATH_FILE_LEN dup (0)
  19. TARGET_PATH     db      PATH_FILE_LEN dup (0)
  20. SOURCE_END      dw      0
  21. TARGET_END      dw      0
  22. PC_DOS_VER      db      0
  23. VALID_IN        db      'abcdefghijklmnopqrstuvwxyz,;=',9
  24. VALID_OUT       db      'ABCDEFGHIJKLMNOPQRSTUVWXYZ',4 dup(32)
  25. VALID_NUM       equ     $ - VALID_OUT + 1
  26. ERR_FLAG        db      0
  27. ERR_HEAD        db      10,13,'SREDirect Error - $'
  28. BAD_VERSION     db      'Incorrect PC-DOS Version$'
  29. NO_PARMS        db      'Correct Syntax is:',13,10,10
  30. db      'SRED [d:][source_path]source_filename[.ext] [d:][target_path]$'
  31. FILE_NOT_FOUND  db      'File Not Found$'
  32. PATH_NOT_FOUND  db      'Target Path Not Found$'
  33. PC_DOS_2_PATCH  db      13,10,'or $'
  34. DRIVES_CONFLICT db      'Source and Target Disk Drives Conflict$'
  35. UNDEFINED_ERR   db      'Undefined Error: PC-DOS Function 56H$'
  36. ERR_TAIL        db      10,10,13,' . . . Aborting',10,13,13,'$'
  37. GOOD_MSG        db      ' . . REDirected to . . $'
  38. BAD_MSG1        db      ' . . NOT REDirected . . $'
  39. BAD_MSG2        db      ' . . already exists$'
  40. END_LINE        db      10,13,'$'
  41. prompt          db      '   REDirect (y/n) ? $'
  42. ;
  43. CODE_START:     ; Parse command line into source & target parameters
  44.         mov     dx,offset COPYRIGHT     ; Display copyright notice
  45.         mov     ah,9h
  46.         int     21h
  47.         mov     ah,30h                  ; Get PC-DOS Version
  48.         int     21h
  49.         mov     PC_DOS_VER,al
  50.         mov     si,80h                  ; PSP parameter byte count pointer
  51.         mov     cl,[si]                 ; Move byte count to CL
  52.         xor     ch,ch                   ; Zero CH
  53.         jcxz    NO_PARMS_PASSED         ; If CX is zero, there are no parameters
  54.         mov     dx,cx                   ; Save byte count in dx
  55.         inc     si                      ; Point to parameter area
  56.         mov     di,si                   ; Copy SI to DI for cleanup routine
  57.         cld                             ; Set direction flag to forward
  58. CLEAN_PARMS:    ; Change valid delimiters to blanks, lower to upper case
  59.         lodsb                           ; Load each character to AL
  60.         push    di                      ; Save DI on stack
  61.         mov     di,offset VALID_IN      ; Point to table of valid inputs
  62.         push    cx                      ; Save CX on stack
  63.         mov     cx,VALID_NUM            ; Set CX to number of inputs to look for
  64. repne   scasb                           ; See if any are in AL
  65.         jcxz    CLEAN_END               ; If not, change nothing
  66.         mov     bx,VALID_NUM            ; Set up BX to point to valid output
  67.         sub     bx,cx                   ; This will leave BX one off
  68.         mov     al,VALID_OUT [bx - 1]   ; Load the valid output to AL
  69. CLEAN_END:
  70.         pop     cx                      ; Restore CX
  71.         pop     di                      ; Restore DI
  72.         stosb                           ; Store modified AL back to PSP
  73. loop    CLEAN_PARMS                     ; Loop until CX is zero
  74. ;
  75.         mov     cx,dx                   ; Restore number of bytes in PSP to CX
  76.         mov     dx,2                    ; Set DX to look for up to 2 parameters
  77.         mov     bx,offset SOURCE_FILE   ; Set BX to address of 1st parameter
  78.         mov     al,' '                  ; Set up to scan for first non-blank
  79.         mov     di,81h                  ; Set DI to PC-DOS parameter pointer
  80. FIND_PARMS:     ; Start looking for parameters, load to program storage
  81. repe    scasb                           ; Scan while blanks
  82.         mov     si,di                   ; Set SI to second non-blank byte
  83.         dec     si                      ; Adjust it to first non-blank byte
  84.         inc     cx                      ; Adjust CX to compensate
  85.         jcxz    PARMS_LOADED            ; If CX is zero, no parameters left
  86.         mov     di,bx                   ; Set DI to parameter hold area
  87.         mov     ax,cx                   ; Store CX to first byte of hold area
  88.         stosb                           ; DI is adjusted to second byte here
  89. STORE:  lodsb                           ; Load each byte to AL
  90.         cmp     al,' '                  ; Is it a blank?
  91.         jz      END_STORE               ; Yes, end of this parameter
  92.         stosb                           ; No, store the byte to hold area
  93. END_STORE:
  94.         loopnz  STORE                   ; Keep looking
  95.         sub     [bx],cx                 ; Store number of bytes in each
  96.         jcxz    PARMS_LOADED            ; If CX is zero, no more parameters
  97.         dec     byte ptr [bx]           ; parameter to first byte of hold area
  98.         mov     di,si                   ; Set up to scan for next non-blank
  99.         dec     di                      ; Adjust DI to point to the blank
  100.         inc     cx                      ; Adjust CX to compensate
  101.         dec     dx                      ; Decrement DX counter
  102.         cmp     dx,0                    ; Is DX zero?
  103.         jz      PARMS_LOADED            ; Yes, all expected parameters loaded
  104.         add     bx,PATH_FILE_LEN        ; No, point to next part of hold area
  105.         jmp     FIND_PARMS              ; Go back and look for more
  106. PARMS_LOADED:                           ; All parameters are loaded
  107.         cmp     SOURCE_FILE[0],0        ; If there are no bytes in the
  108.         ja      FIX_UP                  ; SOURCE_FILE, no parameters present
  109. NO_PARMS_PASSED:                        ; Exit with an error if there
  110.         mov     dx,offset NO_PARMS      ; are no parameters passed
  111.         jmp     ERROR_EXIT
  112. FIX_UP:                                 ; Fix SOURCE_FILE and TARGET_PATH
  113.         mov     si,offset SOURCE_FILE   ; For Search and Rename calls
  114.         lodsb                           ; Get Number of bytes
  115.         xor     ah,ah                   ; Zero high byte of AX
  116.         mov     di,si                   ; Move SI to DI for scan
  117.         add     di,ax                   ; Start scan at end of parameter
  118.         dec     di
  119.         mov     cx,ax                   ; Set CX to number of bytes
  120.         mov     al,'\'                  ; Scan for the last '\'
  121.         std                             ; Set direction flag to reverse
  122. repnz   scasb                           ; Scan while not '\'
  123.         jnz     NO_SOURCE_DIR           ; If Zero Flag not set, '\' not found
  124.         add     di,2                    ; Add 2 to DI to point to file name
  125.         jmp     SOURCE_FIXED            ; position
  126. NO_SOURCE_DIR:                          ; No source directory was specified
  127.         add     di,1                    ; Adjust DI
  128.         cmp     SOURCE_FILE[2],':'      ; Check for specified disk drive
  129.         jne     SOURCE_FIXED            ; None present, we're done
  130.         mov     di,offset SOURCE_FILE[3]; Yes, set DI to point to first byte
  131. SOURCE_FIXED:                           ; after ':'
  132.         mov     SOURCE_END,di           ; Move DI to SOURCE_END pointer
  133. ;
  134.         cld                             ; Set direction flag to forward
  135.         mov     si,offset TARGET_PATH   ; Set up to look for '\' present
  136.         lodsb                           ; Get number of bytes
  137.         cmp     al,0                    ; If it's zero, no target specified
  138.         je      NO_TARGET
  139.         xor     ah,ah                   ; Zero high byte of AX
  140.         add     si,ax                   ; Add it to SI to point to end
  141.         dec     si                      ; Decrement SI to adjust
  142.         lodsb                           ; Look at last byte
  143.         mov     di,si                   ; Copy SI to DI
  144.         cmp     al,'\'                  ; Is last byte a '\'?
  145.         je      TARGET_FIXED            ; Yes, everything's fine
  146.         cmp     TARGET_PATH[0],2        ; If TARGET_PATH is 2 bytes long and
  147.         jne     STORE_SLASH             ; is a disk drive specification,
  148.         cmp     TARGET_PATH[2],':'      ; let it default to the current
  149.         je      TARGET_FIXED            ; directory.
  150. STORE_SLASH:                            ; Place a '\' at the end of
  151.         mov     al,'\'                  ; TARGET_PATH if user did
  152.         stosb                           ; not
  153. TARGET_FIXED:
  154.         mov     TARGET_END,di           ; Move DI to TARGET_END pointer
  155.         jmp     FIND_FILE
  156. NO_TARGET:                              ; Set up to allow target path default
  157.         mov     TARGET_END,offset TARGET_PATH + 1       ; to current path
  158. FIND_FILE:
  159.         mov     dx,offset SOURCE_FILE + 1       ; DX points to SOURCE_FILE
  160.         mov     ah,4eh                  ; Request function 4EH (find 1st file)
  161.         mov     cx,0                    ; Set CX to zero for normal files only
  162.         int     21h                     ; Call PC-DOS
  163.         jnc     FOUND_FILE              ; If no error, first file found
  164.         mov     dx,offset FILE_NOT_FOUND        ; If no files found, exit
  165.         jmp     ERROR_EXIT                      ; program with error message
  166. FOUND_FILE:
  167.         mov     di,SOURCE_END           ; DI points to end of source path
  168.         mov     si,9eh                  ; SI points to default DTA in PSP
  169.         mov     cx,13                   ; DTA will have 13 bytes
  170. rep     movsb                           ; Move bytes to SOURCE_FILE
  171.         mov     di,TARGET_END           ; DI points to end of target path
  172.         mov     si,9eh                  ; SI points to default DTA in PSP
  173.         mov     cx,13                   ; DTA will have 13 bytes
  174. rep     movsb                           ; Move bytes to TARGET_PATH
  175. ;
  176.         mov     dx,offset SOURCE_FILE + 1       ; DX points to old file name
  177.         mov     di,offset TARGET_PATH + 1       ; DI points to new file name
  178.         call    promptYN                ;prompt (y/n) for redirect
  179.         mov     ah,56h                  ; Request function 56H (rename file)
  180.         int     21h                     ; Call PC-DOS
  181.         jnc     GOOD_RED                ; If no error, call was successful
  182.         cmp     ax,3                    ; Check for error 3 (path not found)
  183.         jne     ERR_5
  184.         mov     dx,offset PATH_NOT_FOUND
  185.         jmp     ERROR_EXIT              ; Exit program with error message
  186. ERR_5:  cmp     ax,5                    ; Check for error 5 (file inaccessible)
  187.         jne     ERR_17
  188.         mov     ERR_FLAG,1              ; Soft error -
  189.         call    RED_MSG                 ; Issue message with subroutine
  190.         jmp     NEXT_FILE               ; and keep going
  191. ERR_17: cmp     ax,17                   ; Check for error 17 (drive conflict)
  192.         jne     UNDEF
  193.         mov     dx,offset DRIVES_CONFLICT
  194.         jmp     ERROR_EXIT              ; Exit program with error message
  195. UNDEF:  mov     dx,offset UNDEFINED_ERR ; Undefined error from function 56H
  196.         jmp     ERROR_EXIT              ; Exit program with error message
  197. GOOD_RED:
  198.         mov     ERR_FLAG,0              ; Set error flag off and
  199.         call    RED_MSG                 ; issue message with subroutine
  200. NEXT_FILE:                              ; Look for next file
  201.         mov     ah,4fh                  ; Request function 4FH (find next file)
  202.         mov     cx,0
  203.         int     21h
  204.         jnc     FOUND_ANOTHER           ; No error, another file was found
  205.         jmp     END_OK                  ; Error, we're done finding files
  206. FOUND_ANOTHER:
  207.         jmp     FOUND_FILE              ; Go process next file
  208. END_OK: int     20h                     ; Exit to PC-DOS
  209.  
  210. ERROR_EXIT:                             ; Print Error Message and Exit
  211.         push    dx                      ; Save error message pointer on stack
  212.         mov     ah,9                    ; Display error header
  213.         mov     dx,offset ERR_HEAD
  214.         int     21h
  215.         mov     ah,9                    ; Display error message
  216.         pop     dx
  217.         int     21h
  218.         mov     ah,9                    ; Display error tail
  219.         mov     dx,offset ERR_TAIL
  220.         int     21h
  221.         int     20h                     ; Exit to PC-DOS
  222. ;
  223. RED_MSG proc    near    ; Display message for each file
  224.         mov     cx,2                    ; 2 fields - source & target file
  225.         mov     bx,offset SOURCE_FILE + 1       ; Point to source file
  226. START1: mov     si,bx                   ; Copy BX to SI
  227. START2: lodsb                           ; Load each byte to AL
  228.         cmp     al,0                    ; If ASCII 0, end of field
  229.         je      BETWEEN
  230.         mov     dl,al                   ; Copy byte to DL for funciton 2H
  231.         mov     ah,2h                   ; Request function 2H
  232.         int     21h                     ; Call PC-DOS
  233.         jmp     START2                  ; Get next character
  234. BETWEEN:cmp     cx,2                    ; Is it first or second field?
  235.         jne     CR_LF                   ; If second, display end of message
  236.         cmp     ERR_FLAG,0              ; Is this a success message?
  237.         jz      OK1                     ; Yes, go use GOOD_MSG
  238.         mov     dx, offset BAD_MSG1     ; No, display first part of BAD_MSG
  239.         mov     ah,9h                   ; Request function 9H
  240.         int     21h                     ; Call PC-DOS
  241.         jmp     NEXT                    ; Go process next field
  242. OK1:    mov     dx,offset GOOD_MSG      ; Display GOOD_MSG
  243.         mov     ah,9h                   ; Request function 9H
  244.         int     21h                     ; Call PC-DOS
  245.         jmp     NEXT                    ; Go process next field
  246. CR_LF:  cmp     ERR_FLAG,0              ; Is this a success message?
  247.         jz      OK2                     ; Yes, go terminate message
  248.         mov     dx,offset BAD_MSG2      ; No, display second part of BAD_MSG
  249.         mov     ah,9h                   ; Request function 9H
  250.         int     21h                     ; Call PC-DOS
  251. PC_DOS_2:                               ; Patch for incorrect error
  252.         cmp     PC_DOS_VER,3            ; return in PC-DOS 2.0 and 2.1
  253.         jae     OK2
  254.         mov     dx,offset PC_DOS_2_PATCH
  255.         mov     ah,9h
  256.         int     21h
  257.         mov     dx,offset PATH_NOT_FOUND
  258.         int     21h
  259. OK2:    mov     dx,offset END_LINE      ; Terminate display line
  260.         mov     ah,9h                   ; Request function 9H
  261.         int     21h                     ; Call PC-DOS
  262. NEXT:   add     bx,PATH_FILE_LEN        ; Move BX to point to next field
  263.         loop    START1                  ; Loop for second field
  264.         ret                             ; Or end and return to callint point
  265. RED_MSG         endp
  266.  
  267. promptYN proc near
  268.         push di                         ;save these guys
  269.         push dx                         ;they point to the file name
  270.         call    display_file_name       ;display the file name
  271.         lea     dx,prompt               ;display prompt
  272.         mov     ah,09h                  ;request DOS display
  273.         int     21h                     ;call DOS
  274.         mov     ah,1                    ;request keyboard input
  275.         int     21h                     ;call DOS
  276.         cmp     al,'y'                  ;was the key hit a 'y'
  277.         je      redit                   ;yes - redirect file
  278.         cmp     al,'Y'                  ;no - was the key hit a 'Y'
  279.         je      redit                   ;yes - redirect file
  280.         jmp     next_file               ;no - skip file, get the next
  281. redit:
  282.         lea     dx,end_line             ;force a line feed
  283.         mov     ah,09h                  ;with DOS
  284.         int     21h                     ;call DOS
  285.         pop dx                          ;restore the pointers
  286.         pop di
  287.         ret                             ;get back
  288. promptYN endp
  289.  
  290. display_file_name proc near
  291.          push dx                         ;save them again
  292.          push di                         ;it doesn't hurt
  293.          lea     dx,end_line             ;line feed
  294.          mov     ah,09h                  ;request DOS service
  295.          int     21h                     ;call DOS
  296.          mov     cx,1                    ; 2 fields - source & target file
  297.          mov     bx,offset SOURCE_FILE + 1       ; Point to source file
  298. STARTA:  mov     si,bx                   ; Copy BX to SI
  299. STARTB:  lodsb                           ; Load each byte to AL
  300.          cmp     al,0                    ; If ASCII 0, end of field
  301.          je      NEXTA
  302.          mov     dl,al                   ; Copy byte to DL for funciton 2H
  303.          mov     ah,2h                   ; Request function 2H
  304.          int     21h                     ; Call PC-DOS
  305.          jmp     STARTB                  ; Get next character
  306. NEXTA:   add     bx,PATH_FILE_LEN        ; Move BX to point to next field
  307.          loop    STARTA                  ; Loop for second field
  308.          pop  di                         ;restore them
  309.          pop  dx
  310.          ret                             ; Or end and return to callint point
  311. display_file_name endp
  312.  
  313. RED     ends
  314.         end     BEGIN
  315.